package dao.impl;

import bean.Grade;
import dao.GradeDao;
import util.DBUtil;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class GradeDaoImpl extends DBUtil implements GradeDao {

    @Override
    public List<Grade> getList() {

        List<Grade> grades = new ArrayList<>();

        try {
            String sql = " select * from grade ";

            resultSet = query(sql);

            while (resultSet.next()){
                Grade grade = new Grade();
                grade.setGradeId(resultSet.getInt("gradeid"));
                grade.setGradeName(resultSet.getString("gradename"));
                grades.add(grade);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            closeAll();
        }


        return grades;
    }
}
